<?php defined('SYSPATH') or die();?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>提现-思途CMS{$coreVersion}</title>
    {template 'stourtravel/public/public_js'}
    {php echo Common::getCss('style.css,base.css,base2.css,plist.css,base_new.css,order.css'); }
    {php echo Common::getScript("choose.js,hdate/hdate.js"); }
    {php echo Common::getCss('hdate.css','js/hdate'); }
</head>
<style>
    /*搜索*/

</style>
<body style="overflow:hidden">
<table class="content-tab">
    <tr>
        <td width="119px" class="content-lt-td" valign="top">
            {template 'stourtravel/public/leftnav'}
            <!--右侧内容区-->
        </td>
        <td valign="top" class="content-rt-td" style="overflow:hidden">
        	<div class="cfg-header-bar">
                <div class="fl select-box w100 mt-3 ml-10">
                    <select name="status" id="status" onchange="mysearch()" class="select">
                        <option value="-1">提现状态</option>
                        <option value="0">申请中</option>
                        <option value="1">已完成</option>
                        <option value="2">未通过</option>
                    </select>
                </div>
                <div class="cfg-header-search derive_tb">
                    <div class="fl mt-5 mr-10">时间:</div>
                    <input type="text" value="" id="starttime" placeholder="开始日期" autocomplete="off" style="height: 28px;padding:0 5px" class="time_box" onclick="calendar.show({ id: this })" />

                    <input type="text" id="endtime" class="time_box" placeholder="结束日期" autocomplete="off" style="height: 28px;margin-left:3px;padding:0 5px" onclick="calendar.show({ id: this })" />
                </div>
        		<div class="cfg-header-search">
        			<input type="text" id="searchkey" placeholder="电话/联系人" class="search-text">
                    <a href="javascript:;" class="search-btn" onclick="mysearch()">搜索</a>
        		</div>
        		<a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
                <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10 btn_excel">导出Excel</a>
        	</div>
            <div id="product_grid_panel" class="content-nrt" >

            </div>
        </td>
    </tr>
</table>
<script>

window.display_mode = 1;	//默认显示模式
window.product_kindid = 0;  //默认目的地ID

window.statusmenu={json_encode($statusnames)};

Ext.onReady(
    function () {
        Ext.tip.QuickTipManager.init();
        //产品store
        window.product_store = Ext.create('Ext.data.Store', {

            fields: [
                'id',
                'memberid',
                'way',
                'nickname',
                'mobile',
                'withdrawamount',
                'addtime',
                'finishtime',
                'status',
                'status_name'

            ],

            proxy: {
                type: 'ajax',
                api: {
                    read: SITEURL+'{$prefix_url}/withdraw/aduit/action/read/',  //读取数据的URL
                    update: SITEURL+'{$prefix_url}/withdraw/aduit/action/save/',
                    destroy: SITEURL+'{$prefix_url}/withdraw/aduit/action/delete/'
                },
                reader: {
                    type: 'json',   //获取数据的格式
                    root: 'lists',
                    totalProperty: 'total'
                }
            },

            remoteSort: true,
            pageSize: 20,
            autoLoad: true,
            listeners: {
                load: function (store, records, successful, eOpts) {

                    if(!successful){
                        ST.Util.showMsg("{__('norightmsg')}",5,1000);
                    }
                    var pageHtml=ST.Util.page(store.pageSize,store.currentPage,store.getTotalCount(),10);
                    $("#line_page").html(pageHtml);
                    window.product_grid.doLayout();
                    $(".pageContainer .pagePart a").click(function () {
                        var page = $(this).attr('page');
                        product_store.loadPage(page);
                    });

                }
            }

        });

        //产品列表
        window.product_grid = Ext.create('Ext.grid.Panel', {
            store: product_store,
            renderTo: 'product_grid_panel',
            border: 0,
            width: "100%",
            bodyBorder: 0,
            bodyStyle: 'border-width:0px',
            scroll:'vertical', //只要垂直滚动条
                bbar: Ext.create('Ext.toolbar.Toolbar', {
                store: product_store,  //这个和grid用的store一样
                displayInfo: true,
                emptyMsg: "",
                items: [
                    {
                        xtype:'panel',
                        id:'listPagePanel',
                        html:'<div id="line_page"></div>'
                    },
                    {
                        xtype: 'combo',
                        fieldLabel: '每页显示数量',
                        width: 170,
                        labelAlign: 'right',
                        forceSelection: true,
                        value: 20,
                        store: {fields: ['num'], data: [
                            {num: 20},
                            {num: 40},
                            {num: 60}
                        ]},
                        displayField: 'num',
                        valueField: 'num',
                        listeners: {
                            select:CHOOSE.changeNum
                        }
                    }

                ],

                listeners: {
                    single: true,
                    render: function (bar) {
                        var items = this.items;
                       // bar.down('tbfill').hide();

                        bar.insert(0, Ext.create('Ext.panel.Panel', {border: 0, html: ''}));

                        bar.insert(1, Ext.create('Ext.toolbar.Fill'));
                        //items.add(Ext.create('Ext.toolbar.Fill'));
                    }
                }
            }),
            columns: [
                {
                    text: '申请时间',
                    width: '10%',
                    dataIndex: 'addtime',
                    align: 'center',
                    border: 0,
                    sortable: false,
                    menuDisabled:true,
                    renderer: function (value, metadata, record) {
                        return value;
                    }

                },
                {
                    text: '手机号',
                    width: '10%',
                    dataIndex: 'mobile',
                    align: 'left',
                    border: 0,
                    sortable: false,
                    menuDisabled:true,
                    renderer: function (value, metadata, record) {
                        return value;
                    }

                },

                {
                    text: '昵称',
                    width: '20%',
                    dataIndex: 'nickname',
                    align: 'left',
                    border: 0,
                    sortable: false,
                    menuDisabled:true,
                    renderer: function (value, metadata, record) {
                        return value;
                    }

                },

                {
                    text: '提现方式',
                    width: '15%',
                    dataIndex: 'way',
                    align: 'left',
                    border: 0,
                    sortable: false,
                    menuDisabled:true,
                    renderer: function (value, metadata, record) {
                       var way_names = {'bank':'银行卡','alipay':'支付宝','weixin':'微信'};
                        return way_names[value];
                    }

                },

                {
                    text: '提现金额',
                    width: '15%',
                    dataIndex: 'withdrawamount',
                    align: 'center',
                    border: 0,
                    sortable: false,
                    menuDisabled:true,
                    renderer: function (value, metadata, record) {
                        return value;
                    }

                },


                {
                    text: '提现状态',
                    width: '10%',
                    dataIndex: 'status',
                    align: 'center',
                    border: 0,
                    sortable: false,
                    menuDisabled:true,
                    renderer: function (value, metadata, record) {
                        var status_name = record.get('status_name');
                        return status_name;
                    }

                },
                {
                    text: '完成时间',
                    width: '10%',
                    dataIndex: 'finishtime',
                    align: 'center',
                    border: 0,
                    sortable: false,
                    menuDisabled:true,
                    renderer: function (value, metadata, record) {
                        return value ? value : '--';
                    }

                },



                {
                    text: '操作',
                    width: '10%',
                    align: 'center',
                    border: 0,
                    sortable: false,
                    menuDisabled:true,
                    cls: 'mod-1',
                    renderer: function (value, metadata, record) {

                        var id = record.get('id');
                        var status = parseInt(record.get('status'));

                        var opText = '';
                        if(status === 0){
                            opText = '审核';
                        }else {
                            opText = '详情';
                        }
                        var html = "<a href='javascript:void(0);' class='btn-link' onclick=\"edit(" + id + ")\">"+opText+"</a>";
                        return html;
                        // return getExpandableImage(value, metadata,record);
                    }


                }

            ],
            listeners: {
                boxready: function () {


                    var height = Ext.dom.Element.getViewportHeight();
                    //console.log('viewportHeight:'+height);
                    this.maxHeight = height-90;
                    this.doLayout();
                },
                afterlayout: function (grid) {

                }
            },
            plugins: [
                Ext.create('Ext.grid.plugin.CellEditing', {
                    clicksToEdit: 2,
                    listeners: {
                        edit: function (editor, e) {
                            var id = e.record.get('mid');
                            //  var view_el=window.product_grid.getView().getEl();
                            //  view_el.scrollBy(0,this.scroll_top,false);
                            updateField(0, id, e.field, e.value, 0);
                            return false;

                        }

                    }
                })
            ],
            viewConfig: {

            }
        });


    })

//实现动态窗口大小
Ext.EventManager.onWindowResize(function () {

    var height = Ext.dom.Element.getViewportHeight();
    var data_height = window.product_grid.getView().getEl().down('.x-grid-table').getHeight();
    if (data_height > height - 140)
        window.product_grid.height = (height - 140);
    else
       // delete window.product_grid.height;
    window.product_grid.doLayout();


})







//按进行搜索
function mysearch() {

    var keyword = $.trim($("#searchkey").val());
    var status = $.trim($("#status").val());
    var starttime = $('#starttime').val();
    var endtime = $('#endtime').val();

    window.product_store.getProxy().setExtraParam('endtime',endtime);
    window.product_store.getProxy().setExtraParam('starttime',starttime);
    window.product_store.getProxy().setExtraParam('status',status);
    window.product_store.getProxy().setExtraParam('keyword',keyword);
    window.product_store.loadPage(1);

}


//更新某个字段
function updateField(ele, id, field, value, type) {
    var record = window.product_store.getById(id.toString());

    if (type == 'select') {
        value = Ext.get(ele).getValue();
    }
    Ext.Ajax.request({
        url: SITEURL+"{$prefix_url}/withdraw/action/update/",
        method: "POST",
        datatype: "JSON",
        params: {id: id, field: field, val: value, kindid: 0},
        success: function (response, opts) {
            if (response.responseText == 'ok') {


                record.set(field, value);
                record.commit();
                // view_el.scrollBy(0,scroll_top,false);
            }
        }});

}

//导出excel
$(".btn_excel").click(function(){

    var url=SITEURL+"{$prefix_url}/withdraw/excel";
    ST.Util.showBox('提现审核列表导出',url,580,350,function(){});
})
//查看订单
function edit(id)
{
    var record = window.product_store.getById(id.toString());
    var url=SITEURL+"{$prefix_url}/withdraw/edit/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}id/"+id;
    ST.Util.addTab('提现：'+record.get('nickname'),url,1);
}

</script>

</body>
</html>
